package com.ming.tflitesingleblur.segment;

import android.app.Activity;

import com.ming.tflitesingleblur.segment.operator.EmptyOperator;

import org.tensorflow.lite.support.common.TensorOperator;

import java.io.IOException;

/**
 * Created by glue.wang on 2019/11/13.
 * e-mail:miniminiming@qq.com
 */
public class HumanDanceClassifier extends Classifier {
    /** Float MobileNet requires additional normalization of the used input. */
    /**
     * 观察NormalizeOp类里的代码，如果MEAN=0f.5,STD=255f，此时对于[0, 255]的图像值来说，归一
     * 化以后的数据是[0, 1]
     */
    private static final float IMAGE_MEAN = 0f;

    private static final float IMAGE_STD = 255f;

    /**
     * Float model does not need dequantization in the post-processing. Setting mean and std as 0.0f
     * and 1.0f, repectively, to bypass the normalization.
     *
     * 观察NormalizeOp类里的代码，如果MEAN=0,STD=1，此时是不做任何处理的
     */
    private static final float PROBABILITY_MEAN = 0.0f;

    private static final float PROBABILITY_STD = 1.0f;
    /**
     * Initializes a {@code Classifier}.
     *
     * @param activity
     * @param device
     * @param numThreads
     */
    protected HumanDanceClassifier(Activity activity, Device device, int numThreads) throws IOException {
        super(activity, device, numThreads);
    }

    @Override
    protected String getModelPath() {
        //h5文件通过命令行转化后的模型
//        return "model_dog_cat_h5_cmd.tflite";
        //使用tf.lite.TFLiteConverter转化成的模型
//        return "model_dog_cat_by_api.tflite";
        //saveModel文件夹通过命令行转化后的模型
        return "kaggle_dance_segment.tflite";
    }

    @Override
    protected String getLabelPath() {
        //假的，没用
        return "crack_screen_labels.txt";
    }

    @Override
    protected TensorOperator getPreprocessNormalizeOp() {
        int shape[] = {1, 256, 256, 3};
        //这个模型的输入数据使用tf.keras.preprocessing.image.ImageDataGenerator
        //训练时输入的图也进行了归一化，区间为[0,1]，所以我们这里也处理一下
//        return new InputImageNormalizeOperator(shape);
        //这里把输入数据转化为[0,1]的值，这两个操作符现在是一样的效果
        return new EmptyOperator();
    }

    @Override
    protected TensorOperator getPostprocessNormalizeOp() {
        return new EmptyOperator();

        //这里不对输出数据做任何更改
//        return new NormalizeOp(PROBABILITY_MEAN, PROBABILITY_STD);
    }
}
